<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j">
	
	<a4j:form id="purchaseQueryForm" styleClass="trn_form">
		
		<a4j:outputPanel id="msgContainer" ajaxRendered="true">
				<h:messages globalOnly="false" errorClass="msgError" styleClass="message" infoClass="msgInfo" />
			</a4j:outputPanel>
		<a4j:outputPanel id="purchaseQueryHeadPanel">
			<div id="Form_Table">
				<div id="Form_Row">
					<div class="form_fields">
						<s:label for="pQuerySupplier">Proveedor:</s:label>
						<h:selectOneMenu
							styleClass="input"
							converter="#{supplierConverter}"
							value="#{trnPurchase.purchaseQueryHead.supplierData}"
							id="pQuerySupplier" >
							<a4j:support event="onchange" />
							<s:selectItems 
								value="#{withinHolder.supplierList()}" 
								var="supp"
								label="#{convertAssist.getSupplierName(supp.id)}"
								noSelectionLabel="Proveedor">
							</s:selectItems>
						</h:selectOneMenu>
						<div id="pQuerySupplierMsg" class="inactiveMsg"></div>
					</div>
					<div class="form_fields">
						<s:label for="pQueryStatus">Estado:</s:label>
						<h:selectOneMenu
							styleClass="input"
							value="#{trnPurchase.purchaseQueryHead.status}"
							id="pQueryStatus" >
							<a4j:support event="onchange" />
							<f:selectItem itemValue=""/>
							<f:selectItem itemLabel="PENDIENTE" itemValue="PEND" />
							<f:selectItem itemLabel="CONFIRMADO" itemValue="CONF"/>
							<f:selectItem itemLabel="ANULADO" itemValue="ANUL"/>
							<a4j:support event="onblur" />
						</h:selectOneMenu>
						<div id="pQueryStatusMsg" class="inactiveMsg"></div>
					</div>
					<div class="form_fields">
						<s:label for="pQueryPurchaseDate">Fecha Factura:</s:label>
						<rich:calendar
							inputClass="input"
							id="pQueryPurchaseDate"
							value="#{trnPurchase.purchaseQueryHead.voucherDate}" 
							datePattern="dd/MM/yy"
							buttonClass="field_btn"/>
						<a4j:commandButton
								action="#{trnPurchase.retrieveFilteredPurchases()}"
								id="pQuerySearchBtn"
								value="Buscar" 
								reRender="purchaseQueryForm, purchaseQueryHeadGridPanel "
								styleClass="button"
								style="position:relative; left:10px; padding-bottom:4px; bottom:7px;"
								/>
						<div id="pQueryPurchaseDateMsg" class="inactiveMsg"></div>
					</div>
				</div>
			</div>
			
		</a4j:outputPanel>
		<a4j:outputPanel id="purchaseQueryHeadGridPanel">	
				<rich:datascroller align="center" for="purchaseQueryHeadGrid"
						maxPages="15" page="#{trnPurchase.scrollerPage}"
						renderIfSinglePage="false" />			   			
				<div style="clear: both;" />
				<rich:panel styleClass="table_add" rendered="#{not empty trnPurchase.allPurchaseQueryHead}">
					<rich:dataTable id="purchaseQueryHeadGrid"
						var="purchaseHead" rows="10"
						value="#{trnPurchase.allPurchaseQueryHead}"
						rendered="#{not empty trnPurchase.allPurchaseQueryHead}"
						rowClasses="rvgRowOne,rvgRowTwo"
						style="align:center;">
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Proveedor" /></f:facet>
							<h:outputText value="#{convertAssist.getSupplierName(purchaseHead.idSupplier)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Nro. Factura" /></f:facet>
							<h:outputText value="#{purchaseHead.voucher}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Fecha. Factura" /></f:facet>
							<h:outputText value="#{purchaseHead.voucherDate}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Tipo Compra" /></f:facet>
							<h:outputText value="#{convertAssist.getRefDetDescrip(purchaseHead.buyType)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Cond. Compra" /></f:facet>
							<h:outputText value="#{convertAssist.getBuyConditionDesc(purchaseHead.buyCondition)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Fecha Transaccion" /></f:facet>
							<h:outputText value="#{purchaseHead.startDate}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Moneda" /></f:facet>
							<h:outputText value="#{convertAssist.getCurrencyDescById(purchaseHead.currency)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Total Compra" /></f:facet>
							<h:outputText value="#{purchaseHead.total}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Estado" /></f:facet>
							<h:outputText value="#{purchaseHead.status}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Detalle" /></f:facet>
							<a4j:commandLink id="viewDet"  
							    action="#{trnPurchase.retrivePurchaseDet(purchaseHead.id, 'QUERY')}"
								oncomplete="#{rich:component('modalPurchaseQueryDet')}.show()"
								reRender="modalPurchaseQueryDet"
								immediate="true">
	
								<h:graphicImage id="editImg" url="/img/icons/database_table.png"
									styleClass="actionsImages" />
							</a4j:commandLink>
							<rich:toolTip value="Ver Detalle" for="viewDet" />
						</rich:column>
		
					</rich:dataTable>
				</rich:panel>
			</a4j:outputPanel>
	</a4j:form>
	
	<rich:modalPanel  id="modalPurchaseQueryDet"  minwidth="800" minheight="400" 
		resizeable="false" autosized="true" top="30">
		<f:facet name="header">
			<h:panelGroup>
			<h:outputText value="Detalle de la Compra" />
			</h:panelGroup>
		</f:facet>
		<f:facet name="controls">
			<h:panelGroup>
				<h:graphicImage value="/img/close.png" style="cursor:pointer"
					id="modalPurchaseQueryDetHide" />
				<rich:componentControl for="modalPurchaseQueryDet"
					attachTo="modalPurchaseQueryDetHide" operation="hide" event="onclick" />
			</h:panelGroup>
		</f:facet>
			<rich:panel styleClass="table_add" rendered="#{not empty trnPurchase.allPurchaseQueryDet}">
				<rich:dataTable id="modalPurchaseQueryDetGrid"
						var="purchaseDet" rows="10"
						value="#{trnPurchase.allPurchaseQueryDet}"
						rendered="#{not empty trnPurchase.allPurchaseQueryDet}"
						rowClasses="rvgRowOne,rvgRowTwo"
						style="align:center;">

						<rich:column>
							<f:facet name="header"><h:outputText value="Item" /></f:facet>
							<h:outputText value="#{purchaseDet.item}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Insumo" /></f:facet>
							<h:outputText value="#{convertAssist.getSupplyDesc(purchaseDet.supply)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Cantidad" /></f:facet>
							<h:outputText value="#{purchaseDet.quantity}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Costo" /></f:facet>
							<h:outputText value="#{purchaseDet.grossCost}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Descuento" /></f:facet>
							<h:outputText value="#{purchaseDet.discount}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Recargo" /></f:facet>
							<h:outputText value="#{purchaseDet.charge}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="IVA" /></f:facet>
							<h:outputText value="#{convertAssist.getTaxDesc(purchaseDet.tax)}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Gravadas" /></f:facet>
							<h:outputText value="#{purchaseDet.taxedAmount}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Exentas" /></f:facet>
							<h:outputText value="#{purchaseDet.exemptAmount}" />
						</rich:column>
						
						<rich:column>
							<f:facet name="header"><h:outputText value="Total" /></f:facet>
							<h:outputText value="#{purchaseDet.itemAmount}" />
						</rich:column>
		
					</rich:dataTable>
			</rich:panel>	
	</rich:modalPanel>
	
</ui:composition>